<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript">

    function onSearch() {
        var text = document.getElementById("searchText").value;
        document.getElementById("search").value = text;
        document.getElementById("action").value = "search";
        document.getElementById("form").submit();
    }

    function onPage(page) {
        var text = document.getElementById("searchText").value;
        document.getElementById("search").value = text;
        document.getElementById("page").value = page;
        document.getElementById("action").value = "page";
        document.getElementById("form").submit();
    }

</script>

<h2>My ships</h2>

<form action="myships.do" method="post" id="form">
    <input type="hidden" name="action" id="action">
    <input type="hidden" name="search" id="search">
    <input type="hidden" name="page" id="page">
    <input type="hidden" name="searchOld" value="<c:out value="${searchOld}"/>">
</form>
<table>
    <tr>
        <td>Filter:</td>
        <td><input type="text" name="text" size="30" maxlength="30" id="searchText"
                   value="<c:out value="${searchOld}"/>"/></td>
        <td><input type="button" value="Search" onclick="onSearch();"/></td>
    </tr>
</table>
<c:if test="${numberOfPages gt 0}">
    <table>
        <tr>
            <td>Pages:</td>
            <c:forEach begin="1" end="${numberOfPages}" varStatus="status">
                <td>&nbsp;
                    <c:choose>
                        <c:when test="${currentPageNumber eq status.current}">
                            <c:out value="${status.current}"/>
                        </c:when>
                        <c:otherwise>
                            <a href="#" onclick="onPage(<c:out value="${status.current}"/>)"><c:out
                                    value="${status.current}"/></a>
                        </c:otherwise>
                    </c:choose>
                </td>
            </c:forEach>
        </tr>
    </table>
</c:if>

<table>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Manufacturer</th>
        <th>Action</th>
    </tr>
    <c:forEach items="${spaceShips}" var="ship">
        <tr>
            <td><c:out value="${ship.name}"/></td>
            <td><c:out value="${ship.typename}"/></td>
            <td><c:out value="${ship.manufacturer}"/></td>
            <td><a href="sellship.do?id=<c:out value="${ship.id}"/>">Sell</a></td>
        </tr>
    </c:forEach>
</table>
